import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

import {setStorageSync,getStorageSync} from '@/request/utils.js'

const store = new Vuex.Store({
	state: {
		userInfo: null,
		isLogin: false,
		token: '',
		resolve: ()=>{},
		reject: ()=>{},
	},
	getters: {
		userInfo(state){
			return state.userInfo || getStorageSync('userInfo') || {};
		},
		isLogin(state){
			return state.isLogin || getStorageSync('isLogin');
		},
		token(state){
			return state.token || getStorageSync('token');
		},
	},
	mutations: {
		setLogin(state,bol){
			state.isLogin = bol;
			setStorageSync("isLogin",bol);
		},
		setToken(state,token){
			state.token = token;
			setStorageSync("token",token);
		},
		setUserInfo(state,info){
			state.userInfo = info;
			setStorageSync("userInfo",info);
		},
	},

	actions: {

	}
})

export default store;
